<?php

/**
 * Editing an Activity
 * @package ModuleOrganisationCommunication
 * @version 1.0b
 * @var $_POST['id'] The activity's ID
 */

session_start();

// Configuration file
include '../configuration.php';
// Functions
include '../inc/functions.php';

// Checking if user is logged in
if (!CheckSession()):
	exit();
endif;

// Include all objects
// TODO: Include only needed classes
foreach (glob($configuration['webroot'].'objects/*.php') as $class) { include_once $class; }

try {
	// Format purposes
	$date = explode('/', $_POST['date']);
	$date = $date[2].'-'.$date[1].'-'.$date[0];
	
	// Retrieving activity
	$activity = new Activity();
	$activity->Get($_POST['id']);
	
	$activity->content = $_POST['content'];
	$activity->priority = $_POST['priority'];
	$activity->status = $_POST['status'];
	$activity->progress = $_POST['progress'];
	$activity->title = $_POST['title'];
	$activity->type = $_POST['type'];
	$activity->contactId = $_POST['contact'];
	$activity->crmuserId = $_POST['owner'];
	$activity->date = $date.' '.$_POST['hour'];
	
	// Updating activity into database
	$activity->Save();
	
	echo 'OK';

} catch (Exception $e) {
	echo $e->getMessage();
}
?>